package test0109;


import java.util.ArrayList;
import java.util.List;

public class Test05 {
    public static void main(String[] args) {
        // (5)根据需求写出实现代码

        // 创建公司
        CC c = new CC("IBM");
        // 创建员工
        EE e1 = new EE("张三", 30, 3000);
        EE e2 = new EE("李四", 40, 4000);
        EE e3 = new EE("王五", 50, 5000);
        // 公司添加员工(集合)
        c.add(e1);
        c.add(e2);
        c.add(e3);
        c.add(new EE("赵六", 60, 6000));
        // 打印员工信息
        c.printAll();
        // 找出年龄最大员工
        EE x = c.m1();
        System.out.println(x);
//        // 找出工资最低工资
        EE y = c.m2();
        System.out.println(y);
//        // 找出李四员工
        EE z = c.m3("李四");
        System.out.println(z);
//        // 求平均工资
        double d = c.m4();
        System.out.println(d);
//        // 找工资高于平均工资的员工
        List list = c.m5();
        System.out.println(list);
    }
}

class CC {
    String name;
    EE[] arr = new EE[4];
    int i = 0;

    public void add(EE e1) {
        arr[i]= e1;
        i++;
    }
    public void printAll() {
        for (EE e: arr) {
            System.out.println(e);
        }
    }
    public EE m1() {
        EE max = arr[0];
        for (EE j :arr){
            if (j.getAge()>max.getAge()){
                max = j;
            }
        }
        return max;
    }

    public EE m2() {
        EE min = arr[0];
        for (EE j :arr){
            if (j.getAge()<min.getAge()){
                min = j;
            }
        }
        return min;
    }

    public EE m3(String name) {
        EE a = arr[0];
        for (EE j :arr){
            if (j.getName()==name){
                a = j;
            }
        }
        return a;
    }

    public double m4() {
        double b = 0;
        for (EE j :arr){
            b+=j.getSalary();
        }
        return b/arr.length;
    }

    public List m5() {
        List list = new ArrayList();
        double avg = m4();
        for (EE j :arr){
            if (j.getSalary()>avg){
                list.add(j);
            }
        }
        return list;

    }

    public CC() {
    }

    public CC(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "CC{" +
                "name='" + name + '\'' +
                '}';
    }



}

class EE {
    String name;
    int age;
    int salary;

    public EE() {
    }

    public EE(String name, int age, int salary) {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getSalary() {
        return salary;
    }

    public void setSalary(int salary) {
        this.salary = salary;
    }

    @Override
    public String toString() {
        return "EE{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", salary=" + salary +
                '}';
    }
}
